﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NAudio.Wave;
using NAudio;

namespace T_player
{
    class PlayMedia
    {
        public static IWavePlayer waveOutDevice = null;
        public static AudioFileReader audioFileReader = null;
        public static string clickedFileName = null;

        public static void playMP3(string fileName) {
            PlayMedia pm = new PlayMedia();
            pm.dispose();

            waveOutDevice = new WaveOut();
            if (clickedFileName != null) {
                audioFileReader = new AudioFileReader(clickedFileName);
            }
            else {
                audioFileReader = new AudioFileReader(fileName); 
            }
            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();
        }

        private void dispose() {
            if (waveOutDevice != null) {
                waveOutDevice.Stop();
            }
            if (waveOutDevice != null)
            {
                waveOutDevice.Dispose();
                waveOutDevice = null;
            }
        }
    }
}